<!-- 盈利预测 -->
<template>
  <div class="infoprofit">
    <!-- 评级统计 -->
    <yn-com-comTitle name="评级统计"></yn-com-comTitle>
    <yn-infoprofit-orgRating :data="orgRating"></yn-infoprofit-orgRating>
    <!-- 机构预测（最近一年） -->
    <yn-com-comTitle class="mt15" name="机构预测（最近一年）"></yn-com-comTitle>
    <yn-infoprofit-orgForecast :data="orgForecast"></yn-infoprofit-orgForecast>
    <!-- 预测统计 -->
    <yn-com-comTitle class="mt15" name="预测统计"></yn-com-comTitle>
    <yn-infoprofit-statistic :data="statistic"></yn-infoprofit-statistic>
    <!-- 预测明细 -->
    <yn-com-comTitle class="mt15" name="预测明细"></yn-com-comTitle>
    <yn-infoprofit-detail :data="detail"></yn-infoprofit-detail>
  </div>
</template>

<script>
import { infoprofit } from "../script/api";
var handle = obj => {
  let newObj = {};
  for (let key in obj) {
    if (obj[key].length != 0) {
      newObj[key] = [];
      const mnsj = [
        { acctName: "每股收益" },
        { acctName: "每股净资产" },
        { acctName: "净资产收益率" },
        { acctName: "营业收入" },
        { acctName: "营业利润" }
      ];
      mnsj.forEach(item => {
        obj[key].forEach(i => {
          if (item.acctName == i.acctName) {
            Object.assign(item, i);
          }
        });
      });
      let objs = obj[key].length >= 6 ? obj[key] : mnsj;
      objs.forEach(item => {
        if (item.acctName == "每股收益") {
          newObj[key][0] = item ? item : { acctName: "每股收益", avgVal: "--" };
        }
        if (item.acctName == "每股净资产") {
          newObj[key][1] = item
            ? item
            : { acctName: "每股净资产", avgVal: "--" };
        }
        if (item.acctName == "净资产收益率") {
          newObj[key][2] = item
            ? item
            : { acctName: "净资产收益率", avgVal: "--" };
        }
        if (item.acctName == "营业收入") {
          newObj[key][3] = item ? item : { acctName: "营业收入", avgVal: "--" };
        }
        if (item.acctName == "营业利润") {
          newObj[key][4] = item ? item : { acctName: "营业利润", avgVal: "--" };
        }
      });
    }
  }
  return newObj;
};
export default {
  data() {
    return {
      orgRating: [], //评级统计
      orgForecast: [], //机构预测（最近一年）
      statistic: {}, //预测统计
      detail: [] //预测明细
    };
  },
  components: {},
  computed: {},
  mounted() {
    this.getData();
  },
  methods: {
    async getData() {
      const res = await infoprofit();
      this.orgRating = res.orgRating;
      this.orgForecast = res.orgForecast;
      this.statistic = res.statistic ? handle(res.statistic) : {};
      this.detail = res.detail;
    }
  }
};
</script>
<style lang='scss' scoped>
</style>